package com.mine.wechat.service.Impl;

import com.mine.wechat.dao.WeContDao;
import com.mine.wechat.dao.WeDictDao;
import com.mine.wechat.entity.WeCont;
import com.mine.wechat.entity.WeDict;
import com.mine.wechat.service.WeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class WeServiceImpl implements WeService {

    @Autowired
    private WeDictDao weDictDao;

    @Autowired
    private WeContDao weContDao;

    @Override
    public List<WeCont> findAllWeCont() {
        return weContDao.findAll(new Sort(Sort.Direction.ASC, "id"));
    }

    @Override
    public void insertWeCont(WeCont weCont) {
        weContDao.save(weCont);
    }

    @Override
    public void updateWeCont(WeCont weCont) {
        weCont.setDate(new Date());
        weContDao.save(weCont);
    }

    @Override
    public WeCont findWeContById(Long id) {
        return weContDao.findById(id).get();
    }

    @Override
    public WeDict findWeDictById(Long id) {
        return weDictDao.findById(id).get();
    }

    @Override
    public void deleteWeCont(Long id) {
        weContDao.deleteById(id);
    }

    @Override
    public List<WeDict> findAllWeDict() {
        return weDictDao.findAll(new Sort(Sort.Direction.ASC,"id"));
    }

    @Override
    public void insertWeDict(WeDict weDict) {
        weDictDao.save(weDict);
    }

    @Override
    public void updateWeDict(WeDict weDict) {
        weDictDao.save(weDict);
    }

    @Override
    public void deleteWeDict(Long id) {
        weDictDao.deleteById(id);
    }


}
